#include<cstdio>
#define sr c=getchar()
#define input read()
#define pd (c<'0'||c>'9')
#define fk f=f*10+c-48
#define ps if (c=='-') d=-1
using namespace std;int n,m;
bool b[101][101];char c;
int state[10001][3],father[10001];
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};
int s;
int read()
{
	int d=1,f=0;char c;
	while (sr,pd) ps;fk;
	while (sr,!pd) fk;
	return d*f;
}
void write(int x)
{
	if (!x) return;
	write(x/10);
	putchar(x%10+48);
}
void bfs(int x,int y)
{
	int head=0,tail=1;b[x][y]=false;state[1][1]=x;state[1][2]=y;
	do
	{
		head++;
		for (int i=0;i<4;i++)
		 {
		 	int x=state[head][1]+dx[i];
		 	int y=state[head][2]+dy[i];
		 	if (x>0&&y>0&&x<=m&&y<=n&&b[x][y])
		 	{
		 		tail++;
		 		father[tail]=head;
		 		state[tail][1]=x;
		 		state[tail][2]=y;
		 		b[x][y]=false;
		 	}
		 }
	}while(head<tail);
}
int main()
{
	m=input;n=input;
	for (int i=1;i<=m;i++)
	{
	 for (int j=1;j<=n;j++)
	 {
	 	c=getchar();
	 	if (c>='1'&&c<='9') b[i][j]=true;
	 }
	 c=getchar();
    }
    for (int i=1;i<=m;i++)
     for (int j=1;j<=n;j++)
      	if (b[i][j])
      	{
  	    	bfs(i,j);
    	  	s++;
      	}
    write(s);
}

